import { Component, OnInit, Input, ViewChild } from '@angular/core'; 
import {ClueService } from '../../../../../@core/service/typescript-angular-client/api/clue.service'
import {ClueTableService } from '../../../../../@core/service/clue-service/clue-table.service'
import { catchError, map, tap } from 'rxjs/operators';
import { ClueDataService } from '../../../../../@core/service/clue-service/clue-data.service';


@Component({ 
  selector: 'app-table',
  templateUrl: './table.component.html', 
  styleUrls: ['./table.component.scss']
})
export class TableComponent implements OnInit {
  public total:number = 0;
  public page:number = 1;
  public selectedLimit:number = 10
  public limitOptions:any[] = [10,15,25]
  public pageList:any[];
  public sessionUser:any;
  public sessionDepart:any;
  pageservice: any;
  @ViewChild('paginator')
  pageInator;
  @Input() clue;
  clueTableService: ClueTableService;
  constructor(pageservice:ClueService,clueTableservice:ClueTableService,public cluedata:ClueDataService) {
    this.pageservice = pageservice;
    this.clueTableService = clueTableservice
  }
  ngOnInit() {
    this.cluedata.getDepart();
    this.goToPage({num:this.page,limit:this.selectedLimit}) 
    this.sessionUser=window.sessionStorage.getItem("realName");


  }
  goToPage($event){
    this.page = $event.num; 
    //获取service值
    this.sessionDepart = JSON.parse(sessionStorage.getItem('organizations'))[0];
    let {clueOriginValue, clueStatus, cluePeople,regAuth, clueArea, dataStart,dataEnd,clueHandle,partyName}= this.clueTableService.searchOption;
    if(clueStatus=='-1'){clueStatus =null};
    if(clueOriginValue=='-1'){clueOriginValue =null};
    if(!dataStart){ dataStart = `1970-01-01 00:00:00`}else{dataStart+=` 00:00:00`}
    if(!dataEnd){ dataEnd = `2099-01-01 23:59:59`}else{dataEnd+=` 23:59:59`}
   /*
     * 多条件查询线索信息包含分页信息
     * 返回多个线索信息
     * @param pageIndex 页码
     * @param pageSize 条数
     * @param partyDepart 办理部门
     * @param clueSource 线索来源
     * @param clueStatus 线索状态
     * @param registerPerson 登记人
     * @param registerDepart 登记机关
     * @param registerDate 登记时间开始
     * @param registerDateEnd 登记时间结束
     * @param address 地址
     * @param partyPerson 当前办理人
     * @param partyItem 办理事项
     */


    this.pageservice.findAllByPage($event.num,$event.limit,this.sessionDepart.orgId,clueOriginValue,clueStatus,cluePeople,null,dataStart,dataEnd,clueArea,clueHandle,null,partyName).subscribe((next)=>{
      if(next.data.data){
        this.pageList = next.data.data;
        this.page = next.data.pageIndex;
        this.total = next.data.total;
      }else{
        this.pageList=[];
      }
    },error=>{
      console.log('出错了')
    })
  }
  onNext($event){
    console.log('调用下一页')
    this.goToPage($event)
  }
  onPrev($event){
    console.log('调用上一页')
    this.goToPage($event)
  }
  onFirst($event){
    console.log('调用首页')
    this.goToPage($event)
  }
  onLast($event){
    console.log('调用尾页')
    this.goToPage($event)
  }
  onSelect($event){
    this.selectedLimit = $event;
    
  }


}
